package cn.iocoder.yudao.module.ad.controller.open.form;


import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.ad.service.legaladviceclue.AdLegalAdviceClueService;
import cn.iocoder.yudao.module.ad.service.token.AdTokenService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Objects;

@Tag(name = "广告 - 落地页表单推送")
@RestController
@RequestMapping("/ad/form")
@Validated
public class OpenAdFormController {

    @Resource
    private AdLegalAdviceClueService adLegalAdviceClueService;

    // 渠道识别码
    private static final String CODE = "LEGAL_ADVICE_MP";

    @Operation(description = "广告前置落地页收集的表单线索")
    @PostMapping("/create-clue")
    @OperateLog(enable = false)
    @Parameter(name = "platform", description = "渠道编码；LEGAL_ADVICE_MP = 法律咨询小程序来源")
    public CommonResult<Long> createClue(@RequestParam("platform") String platform, @RequestBody String body) {

        // TODO: 获取渠道对应的 AdBeanFactory: getBean
        // TODO: 处理异步推送来的线索表单数据
        if (Objects.equals(CODE, platform)) {
            return CommonResult.success(adLegalAdviceClueService.createLegalAdviceClueByOpenApi(body));
        }
        return CommonResult.success(0L);
    }

}
